//
//  MainTabBarController.swift
//  1604_LimitFree
//
//  Created by 千锋 on 16/9/26.
//  Copyright © 2016年 Mabin. All rights reserved.
//

import UIKit

class MainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.tabBar.tintColor = UIColor(red: 83.0 / 255.0, green: 156 / 255.0, blue: 255 / 255.0, alpha: 1.0)
        
        
//        UITabBarItem.appearance().setTitleTextAttributes([NSFontAttributeName : UIFont.systemFontOfSize(30)], forState: UIControlState.Selected)
        
        
//        UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.redColor()], forState: .Selected)
        
        //创建管理的子视图控制器
        createViewControllers()
        
    }
    
    
    func createViewControllers()
    {
        //标题
        let titleArray = ["限免","降价","免费","专题","热榜"]
        //图片
        let imageArray = ["tabbar_limitfree","tabbar_reduceprice","tabbar_appfree","tabbar_subject","tabbar_rank"]
        
        //选中的图片
//        let selectorImageArray = ["tabbar_limitfree_press@2x","tabbar_reduceprice_press@2x","tabbar_appfree_press@2x","tabbar_subject_press@2x","tabbar_rank_press@2x"]
        
        //视图控制器对象
        let ctrlArray = ["_604_LimitFree.LimitFreeViewController","_604_LimitFree.ReduceViewViewController","_604_LimitFree.FreeViewController","_604_LimitFree.SubjectViewController","_604_LimitFree.RankViewController"]
        
        var array = Array<UINavigationController>()
        for i in 0..<titleArray.count
        {
            //创建视图控制器
            let ctrlName = ctrlArray[i]
            let cls = NSClassFromString(ctrlName) as! UIViewController.Type
            let ctrl = cls.init()
            
            //设置文字和图片
            ctrl.tabBarItem.title = titleArray[i]
            let imageName = imageArray[i]
            ctrl.tabBarItem.image = UIImage(named: imageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
            //选中的图片
            ctrl.tabBarItem.selectedImage = UIImage(named: (imageName+"_press"))?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
            
            //导航
            let navCtrl = UINavigationController(rootViewController: ctrl)
            
    
            array.append(navCtrl)
        }
        self.viewControllers = array
    }
}
